package greedy;

import java.util.LinkedList;
import java.util.List;

/**
 * @ Author     ：侯耀祖
 * @ Description：
 */
public class partitionLabels {
    public List<Integer> partitionLabels(String s) {
        List<Integer> result = new LinkedList<>();
        int[] edge = new int[26];
        for (int i = 0; i < s.length(); i++) {
            edge[s.charAt(i) - 'a'] = i;
        }
        int idx = 0;
        int lastIdx = -1;
        for (int i = 0; i < s.length(); i++) {
            idx = Math.max(idx, edge[s.charAt(i) - 'a']);
            if (i == idx){
                result.add(i - lastIdx);
                lastIdx = i;
            }
        }
        return result;
    }
}
